
public class Test {
    public static void main() {
        int x = 10 / 3; // 整数除法,结果还是整数
        System.out.println("x is " + x);
        double y = 10.0 / 3; // 浮点数除法
        System.out.println("y is " + y);

        int z = 10 % 3; // 取模运算，求余数
        System.out.println("z is " + z);

        int x1 = 2147483640;
        int y1 = 15;
        int overflow = x1 + y1;
        System.out.println("x1+ y1 is overflow :" + overflow); // -2147483641

        // 自增/自减
        int n = 3300;
        n++; // 3301, 相当于 n = n + 1;
        n--; // 3300, 相当于 n = n - 1;
        System.out.println("n is " + n);

        // 移位运算
        int num = 4;
        System.out.println("num >> 1 is " + (num >> 1)); // 右移1位，相当于除以2
        System.out.println("num << 1 is " + (num << 1)); // 左移1位，相当于乘以2

        // 位运算
        int a = 6; // 二进制 110
        int b = 5; // 二进制 101
        System.out.println("a & b is " + (a & b)); // 按位与 100 = 4
        System.out.println("a | b is " + (a | b)); // 按位或 111 = 7
        System.out.println("a ^ b is " + (a ^ b)); // 按位异或 011 = 3
        System.out.println("~a is " + (~a)); // 按位非 -7 = -(110 + 1) = -(111)

        // 类型自动提升与强制转型
        // 在运算过程中，如果参与运算的两个数类型不一致，那么计算结果为较大类型的整型
        byte b1 = 10;
        byte b2 = 20;
        // byte b3 = b1 + b2; // 错误，b1
        int b3 = b1 + b2; // 正确，结果为int类型
        System.out.println("b3 is " + b3);

        //强制类型转换
        byte b4 = (byte)(b1 + b2); // 强制转型为byte类型
        System.out.println("b4 is " + b4);
    }

}